﻿using AMInstantMessagingServerAPICall;
using AMInstantMessagingServerAPIModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using UDPHelper;

namespace AMInstantMessaging
{
    public partial class FormCreate : Form
    {
        public FormCreate()
        {
            InitializeComponent();
        }

        UserControllerCall _UserControllerCall = new UserControllerCall();

        private void button_register_Click(object sender, EventArgs e)
        {
            if (textBox_password.Text != textBox_confirm.Text)
            {
                MessageBox.Show("两次密码不一致");
                return;
            }

            ThreadHelper.RunInNewThread(() =>
            {
                var register_status = _UserControllerCall.Register(new RegisterModel
                {
                    UserName = textBox_username.Text,
                    DisplayName = textBox_nickname.Text,
                    Password = textBox_password.Text,
                });

                ThreadHelper.RunInMainThread(this, () =>
                {
                    if (register_status.Status != BaseSimpleAPI.StatusDataStatus.Success)
                    {
                        MessageBox.Show(register_status.Message);
                    }
                    else
                    {
                        MessageBox.Show(register_status.Message);
                        Close();
                    }
                });
            });
        }
    }
}
